﻿Imports System.Data.SqlClient

Public Class clsVacaciones
    Private mintidVacacion As Integer
    Private mintidEmpleado As Integer
    Private mdattomaFechainicial As Date
    Private mdattomaFechafinal As Date
    Private mdatesFechainicial As Date
    Private mdatesFechafinal As Date
    Private mstrPeriodo As String
    Private mstrObservaciones As String
    Private mstrCapturo As String
    Private mstrReportado As String


    Public Property idVacacion() As Integer
        Get
            Return mintidVacacion
        End Get
        Set(ByVal value As Integer)
            mintidVacacion = value
        End Set
    End Property
    Public Property idempleado() As Integer
        Get
            Return mintidEmpleado
        End Get
        Set(ByVal value As Integer)
            mintidEmpleado = value
        End Set
    End Property
    Public Property TomaFechainicial() As Date
        Get
            Return mdattomaFechainicial
        End Get
        Set(ByVal value As Date)
            mdattomaFechainicial = value
        End Set
    End Property
    Public Property TomaFechafinal() As Date
        Get
            Return mdattomaFechafinal
        End Get
        Set(ByVal value As Date)
            mdattomaFechafinal = value
        End Set
    End Property
    Public Property esFechainicial() As Date
        Get
            Return mdatesFechainicial
        End Get
        Set(ByVal value As Date)
            mdatesFechainicial = value
        End Set
    End Property
    Public Property esFechafinal() As Date
        Get
            Return mdatesFechafinal
        End Get
        Set(ByVal value As Date)
            mdatesFechafinal = value
        End Set
    End Property
    Public Property Periodo() As String
        Get
            Return mstrPeriodo
        End Get
        Set(ByVal value As String)
            mstrPeriodo = value
        End Set
    End Property
    Public Property Observaciones() As String
        Get
            Return mstrObservaciones
        End Get
        Set(ByVal value As String)
            mstrObservaciones = value
        End Set
    End Property
    Public Property Capturo() As String
        Get
            Return mstrCapturo
        End Get
        Set(ByVal value As String)
            mstrCapturo = value
        End Set
    End Property
    Public Property Reportado() As String
        Get
            Return mstrReportado
        End Get
        Set(ByVal value As String)
            mstrReportado = value
        End Set
    End Property


    Public Sub New()
        mintidVacacion = 0
        mintidEmpleado = 0
        mdattomaFechainicial = Now()
        mdattomaFechafinal = Now()
        mdatesFechainicial = Now()
        mdatesFechafinal = Now()
        mstrPeriodo = ""
        mstrObservaciones = ""
        mstrCapturo = ""
        mstrreportado = 0

    End Sub
   
    Public Sub Borrar()
        Call SetSqlCitra("Delete From Vacaciones Where idVacacion= " & idVacacion)

    End Sub
    Public Sub Buscar()
        Dim cnConn As New sqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = "SELECT * From Vacaciones " & _
        " WHERE idVacacion=" & idVacacion

        Dim rdBuscar As SqlDataReader

        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader

        If rdBuscar.Read() Then
            mintidVacacion = rdBuscar("idVacacion")
            mintidEmpleado = rdBuscar("idempleado")
            mdattomaFechainicial = rdBuscar("tomafechainicial")
            mdattomaFechafinal = rdBuscar("tomafechafinal")
            mdatesFechainicial = rdBuscar("esfechainicial")
            mdatesFechafinal = rdBuscar("esfechafinal")
            mstrPeriodo = rdBuscar("periodo").ToString.Trim
            mstrObservaciones = rdBuscar("observaciones").ToString.Trim
            mstrCapturo = rdBuscar("capturo").ToString.Trim
            mstrReportado = rdBuscar("reportado")

        Else
            mintidVacacion = 0
            mintidEmpleado = 0
            mdattomaFechainicial = Now()
            mdattomaFechafinal = Now()
            mdatesFechainicial = Now()
            mdatesFechafinal = Now()
            mstrPeriodo = ""
            mstrObservaciones = ""
            mstrCapturo = ""
            mstrReportado = 0
        End If

        rdBuscar.Close()
        cnConn.Close()


    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into Vacaciones (" & _
                            "IdVacacion," & _
                            "IdEmpleado," & _
                            "TomaFechaInicial," & _
                            "TomaFechaFinal," & _
                            "EsFechaInicial," & _
                            "EsFechaFinal," & _
                            "Periodo," & _
                            "Observaciones," & _
                            "Capturo," & _
                            "Reportado)" & _
                            "VALUES (" & _
                            "@IdVacacion," & _
                            "@IdEmpleado," & _
                            "@TomaFechaInicial," & _
                            "@TomaFechaFinal," & _
                            "@EsFechaInicial," & _
                            "@EsFechaFinal," & _
                            "@Periodo," & _
                            "@Observaciones," & _
                            "@Capturo," & _
                            "@Reportado)"

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdVacacion", mintidVacacion)
        Command.Parameters.AddWithValue("IdEmpleado", mintidEmpleado)
        Command.Parameters.AddWithValue("TomaFechaInicial", mdattomaFechainicial)
        Command.Parameters.AddWithValue("TomaFechaFinal", mdattomaFechafinal)
        Command.Parameters.AddWithValue("EsFechaInicial", mdatesFechainicial)
        Command.Parameters.AddWithValue("EsFechaFinal", mdatesFechafinal)
        Command.Parameters.AddWithValue("Periodo", mstrPeriodo)
        Command.Parameters.AddWithValue("Observaciones", mstrObservaciones)
        Command.Parameters.AddWithValue("Capturo", mstrCapturo)
        Command.Parameters.AddWithValue("Reportado", mstrReportado)

        cnConn.Open()
        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar las Vacaciones ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
End Class
